package com.tristia.entity;

import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.Table;
import javax.ws.rs.GET;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.xml.bind.annotation.XmlAccessType;
import javax.xml.bind.annotation.XmlAccessorType;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;
import javax.xml.bind.annotation.XmlType;

@Entity
@Table(name = "oauth")
@XmlAccessorType(XmlAccessType.FIELD)
@XmlType(name = "oauth", propOrder = {
	"id",
	"authorizationURL"
})
@XmlRootElement(name = "oauth")
public class OAuthObject {
	@Id 
	@GeneratedValue(strategy = GenerationType.AUTO)
	private long id;
	private String authorizationURL;
	@XmlTransient
	private String consumerKey;
	@XmlTransient
	private String consumerSecret;
	@XmlTransient
	private String token;
	@XmlTransient
	private String tokenSecret;
	
	public OAuthObject() {
		super();
		// TODO Auto-generated constructor stub
	}
	
	public OAuthObject(long id, String authorizationURL) {
		this.id = id;
		this.authorizationURL = authorizationURL;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public String getAuthorizationURL() {
		return authorizationURL;
	}

	public void setAuthorizationURL(String authorizationURL) {
		this.authorizationURL = authorizationURL;
	}
	
    public String getConsumerKey() {
		return consumerKey;
	}

	public void setConsumerKey(String consumerKey) {
		this.consumerKey = consumerKey;
	}

	public String getConsumerSecret() {
		return consumerSecret;
	}

	public void setConsumerSecret(String consumerSecret) {
		this.consumerSecret = consumerSecret;
	}

	public String getToken() {
		return token;
	}

	public void setToken(String token) {
		this.token = token;
	}

	public String getTokenSecret() {
		return tokenSecret;
	}

	public void setTokenSecret(String tokenSecret) {
		this.tokenSecret = tokenSecret;
	}

	@GET
    @Produces({MediaType.APPLICATION_XML, MediaType.TEXT_XML, MediaType.APPLICATION_JSON})
    public OAuthObject getXml() {
        return this;
    }

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime
				* result
				+ ((authorizationURL == null) ? 0 : authorizationURL.hashCode());
		result = prime * result + (int) (id ^ (id >>> 32));
		return result;
	}

	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		OAuthObject other = (OAuthObject) obj;
		if (authorizationURL == null) {
			if (other.authorizationURL != null)
				return false;
		} else if (!authorizationURL.equals(other.authorizationURL))
			return false;
		if (id != other.id)
			return false;
		return true;
	}

	@Override
	public String toString() {
		return "OAuthObject [id=" + id + ", authorizationURL=" + authorizationURL
				+ "]";
	}
    
}
